package com.dongjiantong.web.protal.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dongjiantong.common.exceptions.HttpCode;
import com.dongjiantong.common.model.Response;
import com.dongjiantong.openplatform.annotations.OpenBean;
import com.dongjiantong.openplatform.annotations.OpenMethod;
import com.dongjiantong.sys.model.DicData;
import com.dongjiantong.sys.service.DicDataService;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by mz on 9/1/18.
 *
 */
@Slf4j
@OpenBean
public class ReportStatusController {

    @Reference(version = "1.0.0")
    private DicDataService dicDataService;

    @OpenMethod(
            key = "web.get.breed.report.status",
            httpMethods = RequestMethod.GET
    )
    public Response<List<Map<String , Object>>> getBreedReportStatus(){
        try{
            List<DicData> dicDataList = dicDataService.queryDicByGroup("breedReportStatus");
            List<Map<String , Object>> breedReportStatusList = new ArrayList<>();
            for(DicData dicData : dicDataList){
                Map<String , Object> map = Maps.newHashMap();
                map.put("value",dicData.getDicValue());
                map.put("label",dicData.getDicName());
                breedReportStatusList.add(map);
            }
            return Response.ok(breedReportStatusList);
        }catch (Exception e){
            return Response.fail(HttpCode.INTERNAL_SERVER_ERROR.getCode(),HttpCode.INTERNAL_SERVER_ERROR.getMessage());
        }
    }

    @OpenMethod(
            key = "web.get.supervision.record.status",
            httpMethods = RequestMethod.GET
    )
    public Response<List<Map<String , Object>>> getSupervisionRecordStatus(){
        try{
            List<DicData> dicDataList = dicDataService.queryDicByGroup("supervisionStatus");
            List<Map<String , Object>> breedReportStatusList = new ArrayList<>();
            for(DicData dicData : dicDataList){
                Map<String , Object> map = Maps.newHashMap();
                map.put("value",dicData.getDicValue());
                map.put("label",dicData.getDicName());
                breedReportStatusList.add(map);
            }
            return Response.ok(breedReportStatusList);
        }catch (Exception e){
            return Response.fail(HttpCode.INTERNAL_SERVER_ERROR.getCode(),HttpCode.INTERNAL_SERVER_ERROR.getMessage());
        }
    }
}
